﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Atom;
using YouHP.Logic;


namespace YouHP.Pages.TreatmentHistory
{
    public class PrescriptionList : YouHP.Pages.PatientBasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected List<PrescriptionHistoryInfo> PrescriptionHistoryList;
        protected PrescriptionInfo presData;
        protected int PageCount;
        protected int PageIndex;
        protected int PageSize = 10;
        protected string PagingString = "";
        protected int DataCount = 0;

        protected const int GraphHeight = 140;
        protected string GraphPath;

        protected PrescriptionHistoryInfo CurPresHistory;

        protected new void HandleCommon()
        {
            this.AddLocation("治疗记录", "/PrescriptionHistory/Index.aspx");
            this.AddLocation("治疗详情", "");
            this.SetTitle("治疗详情");
        }

        protected new void HandlePost()
        {

        }

        protected new void HandleGet()
        {
            PageIndex = RequestTools.GetQueryInt("page", 1);
            int prescriptionid = RequestTools.GetQueryInt("prescriptionid", 0);

            if (prescriptionid <= 0)
            {
                this.AddErrLine("无效的参数");
                return;
            }

            presData = PrescriptionBLL.Instance.GetPrescriptionInfo(prescriptionid);
            if (presData.Id <= 0)
            {
                this.AddErrLine("无效的参数");
                return;
            }

            PrescriptionHistoryLogic prescHistLogic = new PrescriptionHistoryLogic();
            PrescriptionHistoryList = prescHistLogic.GetHistories(PrData.Id, prescriptionid, PageSize, PageIndex, out PageCount);

            if (PrescriptionHistoryList.Count > 0)
            {
                CurPresHistory = PrescriptionHistoryList[PrescriptionHistoryList.Count - 1];
            }

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");

            PagingString = this.GetPagingString(
                PageIndex,
                PageCount,
                "/PrescriptionHistory/List.aspx" + query, "page");

            TempUrl = "/PrescriptionHistory/PrescriptionAjax.aspx?prescriptionid=" + presData.Id;
            GraphPath = GetUrl(TempUrl);

        }
    }
}